﻿using System.Collections.Generic;
using DoDoveFramework;
using UnityEngine;
using UnityEngine.InputSystem;

namespace DoDove
{
    public interface IInputHandler
    {
        void Register(InputManager input);
    }

    public abstract class InputHandler : IInputHandler
    {
        public InputManager inputManager;
        public void Register(InputManager input)
        {
            inputManager= input;
            OnRegister();
        }


        protected abstract void OnRegister();
    }

    public class InputManager:Singleton<InputManager>
    {
        
        private DoDoveInputAction _curInputActions; 
        public DoDoveInputAction CurInputActions => _curInputActions;
        private InputActionMap _curMap;
        public InputActionMap CurMap => _curMap;

        protected override void Initialize()
        {
            _curInputActions = new DoDoveInputAction();
        }

        //扩展方法中使用，添加新的map时，要新增扩展方法
        public bool SwitchInputActionMap(InputActionMap map)
        {
            if(map == null) return false;

            if (_curMap == null)
            {
                _curMap = map;
                _curMap.Enable();
                return true;
            }

            if (_curMap.Equals(map)) return false;
            _curMap?.Disable();
            _curMap = map;
            _curMap.Enable();
            return true;
        }

        public void RegisterInputHandler(IInputHandler inputHandler)
        {
            inputHandler.Register(this);
        }
    }
}